package com.gr.experimental.model.impl.distr;

import java.util.List;

import com.gr.experimental.model.impl.distr.operations.CalculationException;
import com.gr.experimental.model.impl.distr.operations.Expression;

public class DoubleArrayValue implements Expression {

	List<Expression> assignmentExpressions;
	
	public DoubleArrayValue(List<Expression> assignmentExpressions){
		
		int i=0;
		for (Expression assignmentExpression: assignmentExpressions) {
			if (Number.class.isAssignableFrom(assignmentExpression.getValueType())) {
				throw new IllegalArgumentException("Expression " + i + " not convertabe to double.");
			}
			i++;
		}
	}
	
	
	
	@Override
	public Object getValue(Context context) throws CalculationException {

		Double[] array = new Double[assignmentExpressions.size()];
		
		for (int i=0; i < assignmentExpressions.size(); i++) {
			Number number = (Number) assignmentExpressions.get(i).getValue(context);
			array[i] = number.doubleValue();
		}
		
		return array;
	}

	@Override
	public Class<?> getValueType() {
		return Double[].class;
	}

}
